2 * Adium is the legal property of its developers, whose names are listed in the copyright file included
3 * with this source distribution.
5 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
6 * General Public License as published by the Free Software Foundation; either version 2 of the License,
7 * or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
10 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
11 * Public License for more details.
13 * You should have received a copy of the GNU General Public License along with this program; if not,
14 * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 #import <Adium/AIContentControllerProtocol.h>
18 #import <Adium/AIInterfaceControllerProtocol.h>
19 #import "AISoundController.h"
20 #import "ESGeneralPreferences.h"
21 #import "ESGeneralPreferencesPlugin.h"
22 #import "PTHotKeyCenter.h"
24 #import "SRRecorderControl.h"
26 #import "AIMessageHistoryPreferencesWindowController.h"
27 #import "AIMessageWindowController.h"
28 #import <Adium/AIServiceIcons.h>
29 #import <Adium/AIStatusIcons.h>
30 #import <AIUtilities/AIColorAdditions.h>
31 #import <AIUtilities/AIFontAdditions.h>
32 #import <AIUtilities/AIImageAdditions.h>
33 #import <AIUtilities/AIMenuAdditions.h>
34 #import <AIUtilities/AIPopUpButtonAdditions.h>
36 #define PREF_GROUP_DUAL_WINDOW_INTERFACE @"Dual Window Interface"
37 #define KEY_TABBAR_POSITION @"Tab Bar Position"
39 @interface ESGeneralPreferences (PRIVATE)
40 - (NSMenu *)tabChangeKeysMenu;
41 - (NSMenu *)sendKeysMenu;
42 - (NSMenu *)tabPositionMenu;
44 - (NSMenu *)statusIconsMenu;
45 - (NSMenu *)serviceIconsMenu;
46 - (NSArray *)_allPacksWithExtension:(NSString *)extension inFolder:(NSString *)inFolder;
49 @implementation ESGeneralPreferences
51 // XXX in order to edit the nib, you need the ShortcutReporter palette
52 // You can download it at http://evands.penguinmilitia.net/ShortcutRecorder.palette.zip
53 // This comes from http://wafflesoftware.net/shortcut/
55 //Preference pane properties
56 - (NSString *)paneIdentifier
60 - (NSString *)paneName{
61 return AILocalizedString(@"General","General preferences label");
63 - (NSString *)nibName{
64 return @"GeneralPreferences";
68 return [NSImage imageNamed:@"pref-general" forClass:[self class]];
71 //Configure the preference view
74 BOOL sendOnEnter, sendOnReturn;
77 [checkBox_messagesInTabs setState:[[[adium preferenceController] preferenceForKey:KEY_TABBED_CHATTING
78 group:PREF_GROUP_INTERFACE] boolValue]];
79 [checkBox_arrangeByGroup setState:[[[adium preferenceController] preferenceForKey:KEY_GROUP_CHATS_BY_GROUP
80 group:PREF_GROUP_INTERFACE] boolValue]];
83 [checkBox_updatesAutomatic setState:[[NSUserDefaults standardUserDefaults] boolForKey:@"SUCheckAtStartup"]];
84 [checkBox_updatesProfileInfo setState:[[NSUserDefaults standardUserDefaults] boolForKey:@"SUIncludeProfile"]];
85 [checkBox_updatesIncludeBetas setState:[[NSUserDefaults standardUserDefaults] boolForKey:@"AIAlwaysUpdateToBetas"]];
88 [popUp_tabKeys setMenu:[self tabChangeKeysMenu]];
89 [popUp_tabKeys compatibleSelectItemWithTag:[[[adium preferenceController] preferenceForKey:KEY_TAB_SWITCH_KEYS
90 group:PREF_GROUP_CHAT_CYCLING] intValue]];
93 sendOnEnter = [[[adium preferenceController] preferenceForKey:SEND_ON_ENTER
94 group:PREF_GROUP_GENERAL] boolValue];
95 sendOnReturn = [[[adium preferenceController] preferenceForKey:SEND_ON_RETURN
96 group:PREF_GROUP_GENERAL] boolValue];
97 [popUp_sendKeys setMenu:[self sendKeysMenu]];
99 if (sendOnEnter && sendOnReturn) {
100 [popUp_sendKeys compatibleSelectItemWithTag:AISendOnBoth];
101 } else if (sendOnEnter) {
102 [popUp_sendKeys compatibleSelectItemWithTag:AISendOnEnter];
103 } else if (sendOnReturn) {
104 [popUp_sendKeys compatibleSelectItemWithTag:AISendOnReturn];
107 [popUp_tabPositionMenu setMenu:[self tabPositionMenu]];
108 [popUp_tabPositionMenu compatibleSelectItemWithTag:[[[adium preferenceController] preferenceForKey:KEY_TABBAR_POSITION
109 group:PREF_GROUP_DUAL_WINDOW_INTERFACE] intValue]];
112 //[checkBox_confirmOnQuit setState:[[[adium preferenceController] preferenceForKey:KEY_CONFIRM_QUIT
113 // group:PREF_GROUP_CONFIRMATIONS] boolValue]];
116 PTKeyCombo *keyCombo = [[[PTKeyCombo alloc] initWithPlistRepresentation:[[adium preferenceController] preferenceForKey:KEY_GENERAL_HOTKEY
117 group:PREF_GROUP_GENERAL]] autorelease];
118 [shortcutRecorder setKeyCombo:SRMakeKeyCombo([keyCombo keyCode], [shortcutRecorder carbonToCocoaFlags:[keyCombo modifiers]])];
119 [shortcutRecorder setAnimates:YES];
120 [shortcutRecorder setStyle:SRGreyStyle];
122 [self configureControlDimming];
125 //Called in response to all preference controls, applies new settings
126 - (IBAction)changePreference:(id)sender
128 if (sender == popUp_tabKeys) {
129 AITabKeys keySelection = [[sender selectedItem] tag];
131 [[adium preferenceController] setPreference:[NSNumber numberWithInt:keySelection]
132 forKey:KEY_TAB_SWITCH_KEYS
133 group:PREF_GROUP_CHAT_CYCLING];
135 } else if (sender == popUp_sendKeys) {
136 AISendKeys keySelection = [[sender selectedItem] tag];
137 BOOL sendOnEnter = (keySelection == AISendOnEnter || keySelection == AISendOnBoth);
138 BOOL sendOnReturn = (keySelection == AISendOnReturn || keySelection == AISendOnBoth);
140 [[adium preferenceController] setPreference:[NSNumber numberWithInt:sendOnEnter]
142 group:PREF_GROUP_GENERAL];
143 [[adium preferenceController] setPreference:[NSNumber numberWithInt:sendOnReturn]
144 forKey:SEND_ON_RETURN
145 group:PREF_GROUP_GENERAL];
146 } else if (sender == checkBox_updatesAutomatic) {
147 [[NSUserDefaults standardUserDefaults] setBool:[sender state] forKey:@"SUCheckAtStartup"];
148 [self configureControlDimming];
149 } else if (sender == checkBox_updatesProfileInfo) {
150 [[NSUserDefaults standardUserDefaults] setBool:[sender state] forKey:@"SUIncludeProfile"];
151 } else if (sender == checkBox_updatesIncludeBetas) {
152 [[NSUserDefaults standardUserDefaults] setBool:[sender state] forKey:@"AIAlwaysUpdateToBetas"];
156 //Dim controls as needed
157 - (void)configureControlDimming
159 [checkBox_arrangeByGroup setEnabled:[checkBox_messagesInTabs state]];
160 [checkBox_updatesProfileInfo setEnabled:[checkBox_updatesAutomatic state]];
161 [checkBox_updatesIncludeBetas setEnabled:[checkBox_updatesAutomatic state]];
165 * @brief Construct our menu by hand for easy localization
167 - (NSMenu *)tabChangeKeysMenu
169 NSMenu *menu = [[NSMenu allocWithZone:[NSMenu menuZone]] init];
170 #define PLACE_OF_INTEREST_SIGN "\u2318"
171 #define LEFTWARDS_ARROW "\u2190"
172 #define RIGHTWARDS_ARROW "\u2192"
173 #define SHIFT_ARROW "\u21E7"
175 [menu addItemWithTitle:[NSString stringWithFormat:AILocalizedString(@"Arrows (%@ and %@)","Directional arrow keys word"), [NSString stringWithUTF8String:PLACE_OF_INTEREST_SIGN LEFTWARDS_ARROW], [NSString stringWithUTF8String:PLACE_OF_INTEREST_SIGN RIGHTWARDS_ARROW]]
181 [menu addItemWithTitle:[NSString stringWithFormat:AILocalizedString(@"Shift + Arrows (%@ and %@)","Shift key word + Directional arrow keys word"), [NSString stringWithUTF8String:SHIFT_ARROW PLACE_OF_INTEREST_SIGN LEFTWARDS_ARROW], [NSString stringWithUTF8String:SHIFT_ARROW PLACE_OF_INTEREST_SIGN RIGHTWARDS_ARROW]]
185 tag:AISwitchShiftArrows];
187 [menu addItemWithTitle:[NSString stringWithFormat:AILocalizedString(@"Brackets (%@ and %@)","Word for [ and ] keys"), [NSString stringWithUTF8String:PLACE_OF_INTEREST_SIGN "["], [NSString stringWithUTF8String:PLACE_OF_INTEREST_SIGN "]"]]
193 [menu addItemWithTitle:[NSString stringWithFormat:AILocalizedString(@"Curly braces (%@ and %@)","Word for { and } keys"), [NSString stringWithUTF8String:PLACE_OF_INTEREST_SIGN "{"], [NSString stringWithUTF8String:PLACE_OF_INTEREST_SIGN "}"]]
199 return [menu autorelease];
202 - (BOOL)shortcutRecorder:(SRRecorderControl *)aRecorder isKeyCode:(signed short)keyCode andFlagsTaken:(unsigned int)flags reason:(NSString **)aReason
207 - (void)shortcutRecorder:(SRRecorderControl *)aRecorder keyComboDidChange:(KeyCombo)newKeyCombo
209 if (aRecorder == shortcutRecorder) {
210 PTKeyCombo *keyCombo = [PTKeyCombo keyComboWithKeyCode:[shortcutRecorder keyCombo].code
211 modifiers:[shortcutRecorder cocoaToCarbonFlags:[shortcutRecorder keyCombo].flags]];
212 [[adium preferenceController] setPreference:[keyCombo plistRepresentation]
213 forKey:KEY_GENERAL_HOTKEY
214 group:PREF_GROUP_GENERAL];
219 * @brief Construct our menu by hand for easy localization
221 - (NSMenu *)sendKeysMenu
223 NSMenu *menu = [[NSMenu allocWithZone:[NSMenu menuZone]] init];
225 [menu addItemWithTitle:AILocalizedString(@"Enter","Enter key for sending messages")
231 [menu addItemWithTitle:AILocalizedString(@"Return","Return key for sending messages")
237 [menu addItemWithTitle:AILocalizedString(@"Enter and Return","Enter and return key for sending messages")
243 return [menu autorelease];
246 - (NSMenu *)tabPositionMenu
248 NSMenu *menu = [[NSMenu allocWithZone:[NSMenu menuZone]] init];
250 [menu addItemWithTitle:AILocalizedString(@"Top","Position menu item for tabs at the top of the message window")
254 tag:AdiumTabPositionTop];
256 [menu addItemWithTitle:AILocalizedString(@"Bottom","Position menu item for tabs at the bottom of the message window")
260 tag:AdiumTabPositionBottom];
262 [menu addItemWithTitle:AILocalizedString(@"Left","Position menu item for tabs at the left of the message window")
266 tag:AdiumTabPositionLeft];
268 [menu addItemWithTitle:AILocalizedString(@"Right","Position menu item for tabs at the right of the message window")
272 tag:AdiumTabPositionRight];
274 return [menu autorelease];
277 #pragma mark Message history
278 - (IBAction)configureMessageHistory:(id)sender
280 [AIMessageHistoryPreferencesWindowController configureMessageHistoryPreferencesOnWindow:[[self view] window]];